import 'package:flutter/material.dart';

class WaveProgressBar extends StatelessWidget {
  final double max;
  final double value;
  final Color activeColor;
  final Color inActiveColor;
  final double barWidth;
  final double spacing;
  final List<double> widths = [0.34, 0.47, 1, 0.42, 0.63, 0.34, 0.63, 1];

  WaveProgressBar({
    Key? key,
    required this.max,
    required this.value,
    required this.activeColor,
    required this.inActiveColor,
    required this.barWidth,
    required this.spacing,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (context, con) {
      int totalSteps = (con.maxWidth / (barWidth + spacing)).floor();
      int currentStep = (value * totalSteps).floor();
      double maxHeight = con.maxHeight;

      return Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: List.generate(totalSteps, (index) {
          double heightFactorForThisBar =
              widths[index % widths.length] * maxHeight;
          return Container(
            margin:
                EdgeInsets.only(right: index < totalSteps - 1 ? spacing : 0),
            decoration: BoxDecoration(
              color: index < currentStep ? activeColor : inActiveColor,
              borderRadius: BorderRadius.circular(300),
            ),
            width: barWidth,
            height: heightFactorForThisBar,
          );
        }),
      );
    });
  }
}
